﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Demo
{
    class Game
    {
        internal bool Gaming(Role r, Player p)
        {
            int sum=0;
            int rNum=0;
            int pNum=0;
            while (true)
            {
                sum++;
                string A = r.Xingwei();
                string B = p.Xingwei();
                Console.WriteLine($"{p.Name} 出拳：{B}");
                Console.WriteLine($"{r.Name} 出拳：{A} ");
                IsWin(A, B, p.Name, ref rNum, ref pNum);
                while (true)
                {
                    Console.WriteLine("是否开始下一轮？<y/n>");
                    string s = Console.ReadLine();
                    if (s == "y")
                    {
                        break;
                    }
                    else if (s == "n")
                    {
                        bool v = EndGame(r.Name,p.Name,sum,rNum,pNum);
                        return v;
                    }
                    else
                    {
                        Console.WriteLine("您输入有误，请重新输入");
                        continue;
                    }
                }

            }
            
        }

        private bool EndGame(string name1, string name2, int sum, int rNum, int pNum)
        {
            Console.WriteLine("===================================");
            Console.WriteLine($"{name1} VS {name2}");
            Console.WriteLine($"对战次数：{sum}");
            Console.WriteLine();
            Console.WriteLine("姓名\t得分");
            Console.WriteLine($"{name1}\t{rNum}");
            Console.WriteLine($"{name2}\t{pNum}");
            if (rNum > pNum)
            {
                Console.WriteLine($"结果：{name1}赢了，{name2}输了");
            }
            else if (rNum < pNum)
            {
                Console.WriteLine($"结果：{name2}赢了，{name1}输了");

            }
            else {
                Console.WriteLine("平局");
            }
            Console.WriteLine("要开始下一局吗？（y/n）");
            string s = Console.ReadLine();
            if (s=="n") { 
                return false;
            }
            else if (s=="y")
            {
                return true;
            }
            return true;
        }

        public void IsWin(string A, string B, string name, ref int rNum, ref int pNum)
        {
           
            if ((A == "剪刀" && B == "布") || (A == "布" && B == "石头") || (A=="石头" && B=="剪刀"))
            {
                rNum++;
                Console.WriteLine($"笨蛋，{name}输了");
            }
            else if (A==B)
            {
                Console.WriteLine($"和局，真衰！嘿嘿，等着瞧吧！");
            }
            else
            {
                pNum++;
                Console.WriteLine($"恭喜，{name}赢了！");
            }


        }
        
    }
}
